import mapmadsel # to make mad selector load first
from quarkpy.maputils import *
#
#------------ WTF -----------
#
# First we define the slider's dialog, then a Click function
# to bring it up when an appropriate menu-button, and finally
# redefine a bunch of menus to put the Click function on them.
#
#
# see the dialogs in quarkpy.qeditor and plugins.mapsearch
# for commented basic dilaog code. LiveEditDlg is a jazzed
# up descendent of quarkpy.qmacro.dialogbox, adapted for
# dialogs that are supposed to drive things around on the
# screen While U Watch.
#
class SlideDlg (quarkpy.dlgclasses.LiveEditDlg):
#
# dialog layout
#
endcolor = AQUA
size = (150,150)
dfsep = 0.40
dlgdef = """
{
Style = "9"
Caption = "Slide Object Dialog"
along: =
{
Txt = "Along"
Typ = "EU"
Hint = "Movement Along Axis, offset from present position." $0D " Increment 1 or gridstep"
}
sep: = {Typ="S" Txt=" "}
around: =
{
Txt = "Around"
Typ = "EU"
Hint = "Movement Around Axis, offset from preset position." $0D " In degrees, regardless of grid" $0D " But FORCE option will force to grid after movement."
}
sep: = {Typ="S" Txt=" "}
force: =
{
Txt = "Grid"
Typ = "X"
Hint = "Object forced to grid after movement"
}
sep: = { Typ="S" Txt=""}
exit:py = {Txt="" }
}
"""
#
# ---- Click Function
#
#
# First an auxiliary:
#
# delta is the cumulative difference between starting and
# current positions.
# diff is the difference from the last position.
# if there is a gridstep, we want to round diff up or down
# to the gridstep, and revise delta accordingly
#
def gridify(delta, diff, gridstep):
# debug('diff %d, delta %d'%(diff,delta))
if not gridstep:
return delta
orig = delta-diff
(rem, quot) = math.modf(diff/gridstep)
# debug("%d, %d"%(rem,quot))
if diff < 0:
sign = -1
else:
sign = 1
if rem:
# squawk("d: %s, r: %s"%(delta, quot+gridstep))
diff = (quot+sign)*gridstep
return orig+diff
#
# Now for the click
#
def EdgeSlideClick(m):
editor = m.editor
edge = m.tagged
#
# parameters are stuffed into the pack class/object,
# and passed thereby
#
class pack:
"a place to stick stuff"
pack.edge = edge
pack.axis = (edge[0]-edge[1]).normalized
pack.o = m.o
pack.along = 0
pack.around = 0
#
# orig_object is the original, o will be replaced as
# the dlg's changes are executed
#
pack.orig_object=pack.o
#
# this initializes the dialog's values, via code in
# dlgclasses.LiveEdit dialog that runs the function
# passed as its `setup' parameter
#
# pack=pack below is a `closure', which effectively passes
# some locally defined info to the function which is then
# passed as an argument (similar to callbacks in effect,
# but easier to use once you get used to it).
#
def setup(self, pack=pack):
src = self.src
self.axis = set_sign(pack.axis)
self.pack = pack
self.point = pack.edge[0]
src["along"] = str(pack.along)
src["around"] = str(int(pack.around/deg2rad))
#
# And here's the `action' function that gets called
# every time you change the data in the dialog box.
#
def action(self, pack=pack, editor=m.editor):
src = self.src
delta = eval(src["along"]) # cumulative displacement from inital position